package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.HcKeshi;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IHcKeshiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科室Controller
 * 
 * @author
 * @date 2023-02-23
 */
@RestController
@RequestMapping("/system/keshi")
public class HcKeshiController extends BaseController
{
    @Autowired
    private IHcKeshiService hcKeshiService;

    /**
     * 查询科室信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:keshi:list')")
    @GetMapping("/list")
    public TableDataInfo list(HcKeshi hcKeshi)
    {
        //System.out.println("-----------哈哈哈哈-------");
        startPage();
        List<HcKeshi> list = hcKeshiService.selectHcKeshiList(hcKeshi);
        for(HcKeshi k:list){
            System.out.println(k+" ");
        }
        return getDataTable(list);
    }

    /**
     * 导出科室信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:keshi:export')")
    @Log(title = "科室信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HcKeshi hcKeshi)
    {
        List<HcKeshi> list = hcKeshiService.selectHcKeshiList(hcKeshi);
        ExcelUtil<HcKeshi> util = new ExcelUtil<HcKeshi>(HcKeshi.class);
        util.exportExcel(response, list, "科室信息数据");
    }

    /**
     * 获取科室信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:keshi:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hcKeshiService.selectHcKeshiById(id));
    }

    /**
     * 新增科室信息
     */
    @PreAuthorize("@ss.hasPermi('system:keshi:add')")
    @Log(title = "科室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HcKeshi hcKeshi)
    {
        System.out.println("归属库:"+hcKeshi.getBelong());
        return toAjax(hcKeshiService.insertHcKeshi(hcKeshi));
    }

    /**
     * 修改科室信息
     */
    @PreAuthorize("@ss.hasPermi('system:keshi:edit')")
    @Log(title = "科室信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HcKeshi hcKeshi)
    {
        return toAjax(hcKeshiService.updateHcKeshi(hcKeshi));
    }

    /**
     * 删除科室信息
     */
    @PreAuthorize("@ss.hasPermi('system:keshi:remove')")
    @Log(title = "科室信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hcKeshiService.deleteHcKeshiByIds(ids));
    }
}
